<style>
    .layui-table-cell .layui-table-sort {
        display: none;
    }
</style>

<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <div class="layui-form lay-header">
                <div class="toolbar">
                    <div class="layui-form-item lay-query-content">
                        <div class="lay-query-box">
                            <div class="query-lt">
                                <div class="layui-inline">
                                    <label class="layui-form-label">产品类别：</label>
                                    <div class="layui-input-inline">
                                        <input id="productTypeId" type="hidden" name="productTypeId">
                                        <div id="productType"></div>
                                    </div>
                                </div>
                                <!-- 客户名称 -->
                                <div class="layui-inline">
                                    <label class="layui-form-label">客户名称：</label>
                                    <div class="layui-input-inline">
                                        <select id='customerId' name="customerId"
                                                lay-filter="reviewPostId"
                                                class="common-select-search">
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">客户产品编码：</label>
                                    <div class="layui-input-inline">
                                        <input name="customerProCode" id="customerProCode" class="layui-input"
                                               type="text"
                                               placeholder="请输入产品编码" autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">产品状态状态：</label>
                                    <div class="layui-input-inline">
                                        <select name="productStatus" lay-filter="productStatus"
                                                class="common-select-search">
                                            <option value="">状态</option>
                                            <option value="1">待规划</option>
                                            <option value="2">工程规划中</option>
                                            <option value="3">已定型</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">客户产品图号：</label>
                                    <div class="layui-input-inline">
                                        <input name="customerProFigure" id="customerProFigure" class="layui-input"
                                               type="text"
                                               placeholder="请输入图号" autocomplete="off"/>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label w-auto">交货时间：</label>
                                    <div class="layui-input-inline">
                                        <input type="text" class="layui-input" id="givenStartTimed" placeholder="交货时间">
                                    </div>
                                </div>
                            </div>
                            <div class="query-rt">
                                <div class="layui-inline">
                                    <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog"
                                            lay-submit layui-form-keyDownSearch="true">查询
                                    </button>
                                    <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>
                                        重置
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="lay-btn-rows">
                    <div class="lay-btn-box">
                        <div class="lay-btn-lt">
                            <button id="productPlanningZYAdd" type="button" class="layui-btn icon-btn color-reseda">导出</button>
                        </div>
                        <div class="lay-btn-rt">

                        </div>
                    </div>
                </div>
            </div>
            <!-- 表格 -->
            <table class="layui-table" id="productPlanRecordInfo" lay-filter="productPlanRecordInfo"></table>
        </div>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="productPlanningTableBar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">详情</a>
    {{# if(d.productStatus=='待校对'){  }}
    <a class="layui-btn layui-btn-xs" lay-event="proofread">校对</a>
    {{# } }}
    {{# if(d.productStatus=='待审核'){  }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="audit">审核</a>
    {{# } }}
</script>

<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'laydate', 'admin', 'laytpl', 'tableTreeDj', 'config'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var table = layui.table;
        var form = layui.form;
        var config = layui.config;
        var admin = layui.admin;
        var tableTree = layui.tableTreeDj;

        laydate.render({
            elem: '#givenStartTimed'
            ,format:"yyyy-MM-dd"
            ,range: "至"
        });

        // 渲染表格
        var insTb = table.render({
            id: '#productPlanRecordInfo',
            elem: '#productPlanRecordInfo',
            url: config.base + 'enterprise/res/admin/planRecord/list',
            page: true,
            toolbar: true,
            defaultToolbar: ["filter"],
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers', title: '序号', fixed: 'left'}
                ,{field: 'skuCode', title: '物料编码', fixed: 'left'}
                ,{field: 'skuName', title: '物料名称', fixed: 'left'}
                ,{field: 'cusProductFigure', sort: true, title: '产品图号'}
                ,{field: 'productNature', sort: true, title: '性质'}
                ,{field: 'assemblyNature', sort: true, title: '属性'}
                ,{field: 'cusProductType', sort: true, title: '物资类别'}
                ,{field: 'orderCode', sort: true, title: '所属订单编号',width: 150}
                ,{field: 'reviewCode', sort: true, title: '评审记录编号',width: 150}
                ,{field: 'givenPlanningTime', sort: true, title: '计划交货时间',width: 160}
                ,{field: 'productStatus', sort: true, title: '状态'}
                ,{align: 'center', toolbar: '#productPlanningTableBar', title: '操作', width: 220}
            ]],
            done: function (res, curr, count) {
                //移除按钮
                var menuButton = config.getMenuButton(location.hash);
                console.log("menuButtton",menuButton);
                if(menuButton.indexOf("搜索") == -1){
                    $('.layui-form.toolbar').remove();
                }
                if(menuButton.indexOf("修改") == -1){
                    $("[lay-event='edit']").remove();
                }
                if(menuButton.indexOf("删除") == -1){
                    $("[lay-event='del']").remove();
                }
            }
        });

        //初始化产品类别
        admin.initDataSelectTree(true, 'enterprise/product/admin/productType/getTreeData', {limit: 99999}, "productType", null, "产品类别", "productTypeId", function (row) {
            $("input[name='productTypeId']").val(row.arr[0].value)
        });

        //渲染下拉
        form.render('select');

        // 工具条点击事件
        table.on('tool(productPlanRecordInfo)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') { //修改
                showEditModel(data);
            } else if (obj.event === 'detail') { //详情
                showDetailModel(data, "1");
            } else if (obj.event === 'audit') { //审核
                showAuditInfo(data);
            } else if(obj.event === 'proofread'){ //产品规划
                showProductBuilder(data);
            }
        });

        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            data.field.givenStartTimed = $("#givenStartTimed").val();
            insTb.reload({where: data.field, page: {curr: 1}}, 'data');
        });

        // 重置搜索
        form.on('submit(resets)', data => {
            insTb.reload({where: admin.resetSearch(data.field), page: {curr: 1}}, 'data');
        });


        //审核
        function showAuditInfo(data) {
            let title="";
            let path = "";
            if (data.source === "客户订单"){
                admin.putTempData("resProTaskData", data ? data : null);
                title = "客户产品规划审核";
                path = "components/res/planRecord/taskProductProoAduitFrom.html";
            }else{
                admin.putTempData("resProTaskZYData", data ? data : null);
                title = "自研产品规划审核"
                path = "components/res/planRecord/taskProductZYProoAduitFrom.html";
            }
            admin.formOpen({
                type: 1,
                area: ['1580px', '95%'],
                style: 'font-size: 20px;',
                title: title,
                path: path,
                finish: function () {
                    table.reload('productPlanRecordInfo', {});
                }
            });
        }

        //校对
        function showProductBuilder(data) {
            let title="";
            let path = "";
            if (data.source === "客户订单"){
                admin.putTempData("resProTaskData", data ? data : null);
                title = "客户产品规划校对";
                path = "components/res/planRecord/taskProductProofreadFrom.html";
            }else{
                admin.putTempData("resProTaskZYData", data ? data : null);
                title = "自研产品规划校对"
                path = "components/res/planRecord/taskProductZYProofreadFrom.html";
            }
            admin.formOpen({
                type: 1,
                area: ['1580px', '95%'],
                style: 'font-size: 20px;',
                title: title,
                path: path,
                finish: function () {
                    table.reload('productPlanRecordInfo', {});
                }
            });
        }

        //显示详情
        function showDetailModel(data) {
            let title="";
            let path = "";
            if (data.source === "客户订单"){
                admin.putTempData("resProTaskData", data ? data : null);
                title = "客户产品规划详情";
                path = "components/res/planning/taskProductBuilderDetailFrom.html";
            }else{
                admin.putTempData("resProTaskZYData", data ? data : null);
                title = "自研产品规划详情"
                path = "components/res/planning/taskProductZYBuilderDetailFrom.html";
            }
            admin.formOpen({
                type: 1,
                area: ['1580px', '95%'],
                style: 'font-size: 20px;',
                title: title,
                path: path,
                finish: function () {
                    table.reload('productPlanRecordInfo', {});
                }
            });
        }
    });
</script>